package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 李旭
 * @create: 2021-09-13 15:32
 *
 * 基于插件的
 **/
@Configuration
public class DelayedConfig {


    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    //交换机   基于插件  （外来的） 交换机
    @Bean
    public Exchange delayExchange(){
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type", "direct");//路由
        return new CustomExchange(exchange_delay,"x-delayed-message",
                true,false,arguments);
    }

    //bingding
    @Bean
    public Binding bindingDelayedQueueToDelayExchange(@Qualifier(value = "delayedQueue") Queue q){
        return BindingBuilder.bind(q).to(delayExchange()).with(routing_delay).noargs();
    }
}
